package ipebg.mzk.facade.system.service;

import ipebg.mzk.common.util.Page;
import ipebg.mzk.facade.entity.MsAdminFunction;
import ipebg.mzk.facade.entity.MsAdminRoleAuthority;
import ipebg.mzk.facade.entity.MsFunctionOption;
import ipebg.mzk.facade.system.bean.FunctionBean;
import ipebg.mzk.facade.system.bean.FunctionTreeBean;

import java.util.List;

public interface FunctionService {

	/**
	 * 獲取菜單列表，datagrid使用
	 * @param function
	 * @param from
	 * @param length
	 * @return
	 * @throws Exception
	 */
	public Page getFunctionList(MsAdminFunction function, int from, int length) throws Exception;
	
	/**
	 * 將實體轉換為bean，datagrid使用
	 * @param functionList
	 * @return
	 * @throws Exception
	 */
	public List<FunctionBean> toBean(List<MsAdminFunction> functionList) throws Exception;

	/**
	 * 保存or修改菜單
	 * @param function
	 */
	public void saveOrUpdate(MsAdminFunction function);

	/**
	 * 刪除菜單
	 * @param functionId
	 * @return
	 * @throws Exception
	 */
	public boolean deleteFunction(String functionId) throws Exception;

	/**
	 * 根據functionId獲取Function對象
	 * @param functionId
	 * @return
	 */
	public MsAdminFunction findMsAdminFunctionById(String functionId);

	/**
	 * 根據functionCode獲取Function對象
	 * @param functionCode
	 * @return
	 */
	public MsAdminFunction findMsAdminFunctionByCode(String functionCode);
	
	/**
	 * 根據父菜單Id獲取TreeList，共新增or修改時選擇上級菜單使用
	 * @param parentId
	 * @return
	 */
	public List<FunctionTreeBean> getFunctionTreeList(String parentId);
	
	/**
	 * 根據父菜單Id及RoleId獲取TreeList，共角色分配權限時使用
	 * @param roleId
	 * @param parentId
	 * @return
	 */
	public List<FunctionTreeBean> getFunctionTreeListByRoleId(String roleId, String parentId);
	
	/**
	 * 獲取所有的菜單項
	 * @return
	 */
	public List<MsAdminFunction> getAllList();
	
	/**
	 * 根據functionId獲取MsAdminRoleAuthority對象的List
	 */
	public List<MsAdminRoleAuthority> findAuthorityByFunctionId(String functionId) throws Exception;
	
	/**
	 * 根據functionId獲取MsFunctionOption對象的List
	 */
	public List<MsFunctionOption> findOptionByFunctionId(String functionId) throws Exception;
	
	List<MsAdminFunction> findFunctionListByUserId(String userId)throws Exception;
	
	/**
	 * 一一對比數據庫，修改用戶權限
	 * @param roleAuthorityList
	 * @param functionIds
	 * @throws Exception
	 */
	public void updateRoleFunctionByDBRoleFunction(List<MsAdminRoleAuthority> roleAuthorityList, String[] functionIds, String roleId) throws Exception;
}
